package com.ren.scale.controller;


import com.ren.scale.entity.vo.ReclScaleFirstClassify;
import com.ren.scale.service.ReclScaleClassifyService;
import com.ren.utils.result.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author RZY
 * @since 2022-07-14
 */

@Api(tags = "量表分类接口")
@RestController
@RequestMapping("/recl-scale/classify")
public class ReclScaleClassifyController {

    @Autowired
    ReclScaleClassifyService scaleClassifyService;

    @ApiOperation(value = "查询所有分类(包括一二级分类)")
    @GetMapping("")
    public R getAllClassifies() {
        List<ReclScaleFirstClassify> classifies = scaleClassifyService.getAllClassifies();
        return R.ok()
                .data("classifies", classifies);
    }

    @ApiOperation(value = "分类文件上传(默认xlsx文件格式)")
    @PostMapping("/file")
    public R uploadClassifyFile(MultipartFile file) {
        boolean res = scaleClassifyService.addClassifyByFile(file);
        if(res) return R.ok()
                .message("量表分类保存成功!");
        else return R.error()
                .message("文件读取失败，请稍后再试!");
    }

}

